package com.wenhuitec.android.tang.ui.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.dhkj.web.bean.Zweekmenubak;
import com.wenhuitec.android.tang.R;

import java.util.ArrayList;
import java.util.List;

public class SelectFoodsAdapter extends RecyclerView.Adapter<SelectFoodsAdapter.ViewHolder> {
    private Context mcontext;
    private List<Zweekmenubak> list;
    private GvOnClick mGvOnClick;

    public void setList(List<Zweekmenubak> list) {
        this.list = list;
        notifyDataSetChanged();
    }

    public SelectFoodsAdapter(Context context) {
        mcontext = context;
        this.list = new ArrayList<>();
    }

    public void setmGvOnClick(GvOnClick mGvOnClick) {
        this.mGvOnClick = mGvOnClick;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = View.inflate(mcontext, R.layout.item_foodname, null);
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        //这里就是单独控制每一个属性的地方
        holder.btNumber.setText(list.get(position).getName().trim());

        holder.btNumber.setOnClickListener(v -> {
            if (mGvOnClick != null) {
                mGvOnClick.userClick(list.get(position));
            }
        });
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        TextView btNumber;


        ViewHolder(View item) {
            super(item);
            btNumber = item.findViewById(R.id.btNumber);
        }

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public interface GvOnClick {
        void userClick(Zweekmenubak zweekmenubak);
    }
}


